import '../base/stringres.dart';

///文字工具类
class StringUtil {
  ///获取今天的日期
  static String getTodayHealthDate(DateTime todayDate) {
    return formatString(StringRes.main_today_content, [getTodayMonth(todayDate.month), todayDate.day]);
  }

  ///获取今天的标题
  static String getTodayHealthTitle(
      int todayFemaleCycle, int dayByFemaleCycle) {
    switch (todayFemaleCycle) {
      case 2:
        return "${StringRes.follicular_phase} ${formatString(StringRes.what_day, [dayByFemaleCycle])}";
      case 3:
        return "${StringRes.easy_pregnancy} ${formatString(StringRes.what_day, [dayByFemaleCycle])}";
      case 4:
        return StringRes.ovulation_day;
      case 5:
        return "${StringRes.luteal_phase} ${formatString(StringRes.what_day, [dayByFemaleCycle])}";
    }
    return "${StringRes.menstrual_period} ${formatString(StringRes.what_day, [dayByFemaleCycle])}";
  }

  ///获取今天的内容
  static String getTodayHealthContent(int todayFemaleCycle, int distanceFemaleCycle,int distanceOvulationDays) {
    if (todayFemaleCycle == 4) {
      return StringRes.ovulation_content;
    }
    if (distanceFemaleCycle == 0) {
      return formatString(StringRes.female_cycle_content, ["1"]);
    }
    if (todayFemaleCycle == 3 && distanceOvulationDays >= 0) {
      if(distanceOvulationDays == 0){
        return formatString(StringRes.ovulation_countdown_content, ["1"]);
      }
      return formatString(StringRes.ovulation_countdown_content, [distanceOvulationDays]);
    }
    return formatString(StringRes.female_cycle_content, [distanceFemaleCycle]);
  }

  ///获取今天的标题
  static String getCurrentPeriodTitle(String periodTitle) {
    return formatString(StringRes.currently, [periodTitle]);
  }

  ///格式化字符串
  static String formatString(String pattern, List<dynamic> values) {
    int index = 0;
    return pattern.replaceAllMapped(RegExp(r'%d'), (match) {
      if (index < values.length) {
        return values[index++].toString();
      }
      return match.group(0)!;
    });
  }

  ///获取今天的月份
  static String getTodayMonth(int month) {
    switch (month) {
      case 1:
        return StringRes.january;
      case 2:
        return StringRes.february;
      case 3:
        return StringRes.march;
      case 4:
        return StringRes.april;
      case 5:
        return StringRes.may;
      case 6:
        return StringRes.june;
      case 7:
        return StringRes.july;
      case 8:
        return StringRes.august;
      case 9:
        return StringRes.september;
      case 10:
        return StringRes.october;
      case 11:
        return StringRes.november;
      case 12:
        return StringRes.december;
    }
    return StringRes.january;
  }
}
